import SelectUtil from '@/SelectUtil';
import MovementCommon from 'code/Core/Common/MovementCommon';
import SLKCommon from 'code/Core/Common/SLKCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 箭雨
 **/
export default class YX_ArrowRain extends AbilityBase {
    static instance: YX_ArrowRain;
    constructor(id: string = 'Ajy1') {
        super(id);
        YX_ArrowRain.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let missile = SLKCommon.getUnitMissileart(source);
        let speed = SLKCommon.getUnitMissileSpeed(source);
        let radian = SLKCommon.getUnitMissilearc(source);
        let es = SelectUtil.getEnemyUnitsInRange(source, 375, tarX, tarY);
        for (let e of es) {
            MovementCommon.TargetMissile({
                speed,
                missile,
                radian,
                caster: source,
                target: e,
                onReach: this.onMissleReach.bind(this),
            });
        }
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    onMissleReach(p: TargetMissileConfig) {
        let lv = this.getAbilityLevel(p.caster);
        let dmg = 45 * lv + UnitCommon.取攻击(p.caster) * (0.45 + 0.25 * lv);
        DamageSystemInstance.applyAttackDamage(p.target, p.caster, dmg, this.id);
    }
}
